//
//  ShopCollectionReusableView.m
//  Products_B
//
//  Created by lanou on 16/5/30.
//  Copyright © 2016年 朋学友. All rights reserved.
//

#import "ShopCollectionReusableView.h"
@interface ShopCollectionReusableView () 
@end

@implementation ShopCollectionReusableView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        
        UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, kWidth, 100)];
        scrollView.contentSize = CGSizeMake(kWidth + 100, 0);
        scrollView.showsHorizontalScrollIndicator = NO;
        scrollView.showsVerticalScrollIndicator = NO;
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:scrollView.bounds];
        scrollView.scrollEnabled = YES;
        imageView.image = [UIImage imageNamed:@"CookClassRoman.jpg"];
        [scrollView addSubview:imageView];
        imageView.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
        [imageView addGestureRecognizer:tap];
        [self addSubview:scrollView];

        // 创建collectionView
        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
        _smallCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, scrollView.frame.origin.y + scrollView.frame.size.height, kWidth,360 * (kWidth / 2 - 20) / 640 + 10) collectionViewLayout:flowLayout];
        flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        _smallCollectionView.backgroundColor = [UIColor colorWithRed:195 / 255.0 green:195 / 255.0 blue:195 / 255.0 alpha:1];
        _smallCollectionView.showsHorizontalScrollIndicator = NO;
        [self addSubview:_smallCollectionView];
        
        // 固定label
        _label = [[UILabel alloc] initWithFrame:CGRectMake(20, _smallCollectionView.frame.origin.y + _smallCollectionView.frame.size.height + 20, 200, 20)];
        _label.text = @"热门商品";
        _label.alpha = 0.8;
        _label.font = [UIFont systemFontOfSize:14];
        [self addSubview:_label];  
    }
    return self;
}

- (void)tapAction:(UITapGestureRecognizer *)tap {
    if (self.tapBlock) {
        self.tapBlock();
    }
}

@end





